﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;

namespace Zephyris_Space_Mercs_Server
{
    class Helpers
    {
        public static string SubstringByDelimiter(StringBuilder sb, char delimiter)
        {
            StringBuilder result = new StringBuilder(sb.Length);
            for (int i = 0; i < sb.Length; i++)
            {
                if (sb[i] == delimiter)
                {
                    return result.ToString();
                }

                result.Append(sb[i]);
            }

            return string.Empty;
        }

        public static IPEndPoint RemoteEPtoIPEP(EndPoint endPoint)
        {
            string[] endpointVals = endPoint.ToString().Split(':');
            IPEndPoint incomingEndPoint = new IPEndPoint(IPAddress.Parse(endpointVals[0]), int.Parse(endpointVals[1]));
            return incomingEndPoint;
        }

        public static void Logger(string text, bool verbose)
        {
            if (verbose)
            {
                Console.WriteLine(DateTime.Now.ToString() + " - " + text + System.Environment.NewLine);
            }
        }

    }
}
